class Node {
    constructor(data) {
        this.element = data;
        this.next = undefined;
    }
}
class LinkedList {
    constructor() {
        this.head = undefined;
    }
    append(arr) {
        let node = new Node(arr[0]);
        this.head = node;
        for (let i = 1; i < arr.length; i++) {
            node.next = new Node(arr[i]);
            node = node.next;
        }
    }
    reserve(head) {
        if (head.next == null) {
            //返回head;
            return head;
        }
        //调用自身
        let restNode = reserve(head.next);
        //逆置功能
        let current = head.next;
        current.next = head;
        head.next = undefined;
        this.head = restNode;
        return this.head;
    }

}
const arr = [1, 2, 3, 4];
const list = new LinkedList();
list.append(arr);
list.reserve(list.head);
console.log(list.toString())